# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution(object):
    def rotateRight(self, head, k):
        """
        :type head: ListNode
        :type k: int
        :rtype: ListNode
        """
        num_list = []
        node = head
        while node:
            num_list.append(node.val)
            node = node.next
        n = len(num_list)
        index_list = [(i + k) % n for i in range(n)]
        node2 = head
        for i in range(n):
            j = index_list.index(i)
            node2.val = num_list[j]
            node2 = node2.next
        return head